#region using
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Data;
using BLToolkit.Mapping;
using BLToolkit.Data;
using BLToolkit.DataAccess;
using BLToolkit.EditableObjects;
#endregion

namespace Brainsoft.Core.BusinessLogic
{
    /// <summary>
    /// Este objeto representa las propiedades y metodos de ApplicationAdmins.
    /// Nomenclatura a usar para los SP = ApplicationAdmins_SelectByKey , ApplicationAdmins_Update, etc.
    /// En caso contrario usar el nombre de los SP como atributos de la clase, ej:
    ///[ActionSprocName("SelectAll", "NombreProcedimiento")], [ActionSprocName("Insert", "NombreProcedimiento")], etc.
    /// </summary>	

    public class ApplicationAdmins
    {

        #region Constructors
        public ApplicationAdmins()
        {
        }
        #endregion

        #region Private Properties
        private int _idUsuario;
        private int _applicationID;
        #endregion

        #region Public Properties
        public int IdUsuario
        {
            get { return _idUsuario; }
            set { _idUsuario = value; }
        }

        public int ApplicationID
        {
            get { return _applicationID; }
            set { _applicationID = value; }
        }
        #endregion

        #region Relational Properties

        #endregion

        #region Generic Methods

        #region Insert, Update, Delete

        public void Insert(ApplicationAdmins obj)
        {
            Query.Insert(db, obj);
        }

        public void Update(ApplicationAdmins obj)
        {
            Query.Update(db, obj);
        }

        public void Delete(ApplicationAdmins obj)
        {
            Query.Delete(db, obj);
        }

        public void Delete(int id)
        {
            Query.DeleteByKey(db, id);
        }

        #endregion

        #region Select

        public List<ApplicationAdmins> SelectAll()
        {
            return Query.SelectAll(db);
        }

        public ApplicationAdmins SelectByKey(object[] parameters)
        {
            return Query.SelectByKey(db, parameters);
        }

        #endregion

        #region Batch
        public bool BatchInsert(List<ApplicationAdmins> list)
        {
            using (db = new DbManager())
            {
                db.BeginTransaction();
                try
                {
                    foreach (ApplicationAdmins obj in list)
                    {
                        Query.Insert(db, obj);
                    }
                }
                catch
                {
                    db.RollbackTransaction();
                    return false;
                }
                db.CommitTransaction();
                return true;
            }
        }
        public bool BatchUpdate(List<ApplicationAdmins> list)
        {
            using (db = new DbManager())
            {
                db.BeginTransaction();
                try
                {
                    foreach (ApplicationAdmins obj in list)
                    {
                        Query.Update(db, obj);
                    }
                }
                catch
                {
                    db.RollbackTransaction();
                    return false;
                }
                db.CommitTransaction();
                return true;
            }
        }
        #endregion

        #endregion

        #region Custom Methods
        public List<ApplicationAdmins> GetApplicationByUserId(int userId)
        {
            using (DbManager db = new DbManager("Connection String"))
            {
                return db.SetSpCommand("ApplicationAdmins_SelectByUserId",
                    db.Parameter("@IdUsuario", userId)).ExecuteList<ApplicationAdmins>();
            }
        }
        public void DeleteByUserId(int userId)
        {
            using (DbManager db = new DbManager("Connection String"))
            {
                db.SetSpCommand("ApplicationAdmins_DeleteByUserId",
                    db.Parameter("@IdUsuario", userId)).ExecuteNonQuery();
            }
        }
        #endregion

        #region Protected Members

        protected DbManager db;

        private SprocQuery<ApplicationAdmins> _query;
        protected virtual SprocQuery<ApplicationAdmins> Query
        {
            get
            {
                if (null == _query)
                    db = new DbManager("Connection String");
                _query = new SprocQuery<ApplicationAdmins>(db);
                return _query;
            }
        }

        #endregion
    }
}
